use crate::gen_title;

pub fn ch4_7_1() {
    gen_title("ch4_7_1", 18);

    #[derive(Debug)]
    struct HasDrop1;

    #[derive(Debug)]
    struct HasDrop2;

    impl Drop for HasDrop1 {
        fn drop(&mut self) {
            println!("Dropping HasDrop1");
        }
    }

    impl Drop for HasDrop2 {
        fn drop(&mut self) {
            println!("Dropping HasDrop2");
        }
    }

    #[derive(Debug)]
    struct HasTwoDrops {
        one: HasDrop1,
        two: HasDrop2,
    }

    impl Drop for HasTwoDrops {
        fn drop(&mut self) {
            println!("Dropping HasTwoDrops!");
        }
    }

    #[derive(Debug)]
    struct Foo;

    impl Drop for Foo {
        fn drop(&mut self) {
            println!("Dropping Foo!");
        }
    }

    let _x = HasTwoDrops {
        one: HasDrop1,
        two: HasDrop2,
    };

    let _foo = Foo;

    println!("Running");
    println!("{:?}, {:?}", _x, _foo);
}

pub fn ch4_7_2() {
    gen_title("ch4_7_2", 18);

    #[derive(Debug)]
    struct Foo;

    impl Drop for Foo {
        fn drop(&mut self) {
            println!("Dropping Foo!");
        }
    }

    let foo = Foo;
    drop(foo);
}
